package com.opennews.openplatform

import com.opennews.openplatform.constants.ExpenseTypeConstant
import com.opennews.openplatform.constants.IncomeExpenseTypeConstant
import com.opennews.openplatform.constants.IncomeTypeConstant
import grails.compiler.GrailsCompileStatic
import grails.gorm.transactions.Transactional

@Transactional
@GrailsCompileStatic
class IncomeExpenseDetailBaseTypeService {
    /**
     * Prepares all default types.
     */
    void init() {
        if (IncomeExpenseDetailBaseType.count() == 0) {
            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_FAMILY
                title = "日常家庭各类开销"
                subtitle = "如超市、用餐、网购等。"
                orderIndex = 1
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_LIVING_COST
                title = "生活成本"
                subtitle = "如水电煤、通讯费、宽带等。"
                orderIndex = 2
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_EDUCATION
                title = "教育"
                subtitle = "如上课、考试等。"
                orderIndex = 3
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_TRANSPORTATION
                title = "交通"
                subtitle = "如乘车、交通卡充值、加油卡充值等。"
                orderIndex = 4
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_SOCIALIZING
                title = "社交"
                subtitle = "如各类人情、红包等。"
                orderIndex = 5
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_FAMILY_TRAVEL
                title = "家庭旅行"
                subtitle = "包括相关交通费、住宿费、签证费等。"
                orderIndex = 6
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_BUSINESS_TRAVEL
                title = "公务差旅"
                subtitle = "比如先行个人垫付的相关差旅费用。"
                orderIndex = 7
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_FAMILY_CAR
                title = "家用车"
                subtitle = "如车辆维修、保养、车险等。"
                orderIndex = 8
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_FAMILY_INSURANCE
                title = "家庭保险"
                subtitle = "如商业养老、意外、疾病类保险等。"
                orderIndex = 9
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_FAMILY_HEALTH
                title = "家庭健康"
                subtitle = "如就医、购药、健身等。"
                orderIndex = 10
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_INVESTMENT
                title = "投资"
                subtitle = "如定投、股票、房产等。"
                orderIndex = 11
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_CREDIT_CARD_REPAYMENT
                title = "信用卡还款"
                subtitle = "用于信用卡账单还款"
                orderIndex = 12
                analysisIncluded = false
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_PAY_FOR_ANOTHER
                title = "代付"
                subtitle = "用于先行代付的公司、他人的费用。"
                orderIndex = 13
                analysisIncluded = false
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.EXPENSE
                name = ExpenseTypeConstant.EXPENSE_OTHER
                title = "其它"
                subtitle = "其它类费用"
                orderIndex = 14
                save()
            }


            // Prepares the default income types.
            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_COMPANY_SALARY
                title = "公司薪资收入"
                orderIndex = 1
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_COMPANY_BONUS
                title = "公司奖金收入"
                orderIndex = 2
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_COMPANY_REIMBURSEMENT
                title = "公司报销"
                orderIndex = 3
                analysisIncluded = false
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_COMPANY_OTHER_INCOME
                title = "公司其它收入"
                orderIndex = 4
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_INVESTMENT_RETURN
                title = "投资回报"
                orderIndex = 5
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_REFUND
                title = "退款"
                orderIndex = 6
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_PAY_FOR_ANOTHER_REPAYMENT
                title = "代付回款"
                orderIndex = 7
                analysisIncluded = false
                save()
            }

            new IncomeExpenseDetailBaseType().with {
                incomeExpenseType = IncomeExpenseTypeConstant.INCOME
                name = IncomeTypeConstant.INCOME_OTHER
                title = "其它收入"
                orderIndex = 8
                save()
            }
        }
    }
}